package com.cskaoyan.duolai.clean.orders.controller.inner;

import com.cskaoyan.duolai.clean.orders.model.entity.OrdersDO;
import com.cskaoyan.duolai.clean.orders.model.mapper.OrdersMapper;
import com.cskaoyan.duolai.clean.pay.dto.OrderInfoDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 订单服务内部接口
 */
@RestController
@RequestMapping("/inner/orders")
@Api(tags = "内部接口 - 订单服务相关接口")
public class InnerOrdersController {

    @Resource
    private OrdersMapper ordersMapper;

    /**
     * 根据订单ID获取订单信息
     *
     * @param orderId 订单ID
     * @return 订单信息
     */
    @GetMapping("/{orderId}")
    @ApiOperation("根据订单ID获取订单信息")
    public OrderInfoDTO getOrderById(@PathVariable("orderId") Long orderId) {
        OrdersDO ordersDO = ordersMapper.selectById(orderId);
        if (ordersDO == null) {
            return null;
        }

        OrderInfoDTO orderInfoDTO = new OrderInfoDTO();
        BeanUtils.copyProperties(ordersDO, orderInfoDTO);
        return orderInfoDTO;
    }
}
